﻿using System;

namespace OigSync.Infrastructure.Domain
{
    /*
     * 领域模型基类
     */
    public class EntityBase
    {
        /*
         * Entity primary key
         */
        private Object key;

        /*
         * Constructor
         */
        public EntityBase()
        {
            this.key = Guid.NewGuid().ToString();
        }

        public EntityBase(Object akey)
        {
            this.key = akey;
        }

        public override Boolean Equals(Object otherObject)
        {
            if (otherObject == null)
                return false;

            if (!(otherObject is EntityBase))
                return false;

            EntityBase other = otherObject as EntityBase;

            return this.key == other.key;
        }

        public override int GetHashCode()
        {
            return this.key.GetHashCode();
        }

        public static Boolean operator ==(EntityBase leftEntity, EntityBase rightEntity)
        {
            if (leftEntity == null || rightEntity == null)
                return false;

            return leftEntity.key == rightEntity.key;
        }

        public static Boolean operator !=(EntityBase leftEntity, EntityBase rightEntity)
        {
            return !(leftEntity == rightEntity);
        }
    }
}
